package com.sharker.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sharker.R;
import com.sharker.models.TopicBeen;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称：Sharker-master
 * 类描述：
 * 创建人：${丁江楠}
 * 创建时间：2017/4/12 19:12
 * 修改人：${丁江楠}
 * 修改时间：2017/4/12 19:12
 * 修改备注：
 */
public class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.TopicHolder>{
    private Context context;
    private List<TopicBeen> list=new ArrayList<>();

    public TopicAdapter(Context context, List<TopicBeen> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public TopicHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        TopicHolder topicHolder = new TopicHolder(View.inflate(context, R.layout.topic_item, null));
        return topicHolder;
    }

    @Override
    public void onBindViewHolder(TopicHolder holder, int position) {
        TopicBeen topicBeen = list.get(position);
        holder.topic_title.setText(topicBeen.getTitle());
        if(topicBeen.getType().equals("1")){
            holder.topic_type.setText(topicBeen.getLength()+"堂课/视频");
        }else{
            holder.topic_type.setText(topicBeen.getLength()+"堂课/音频");
        }


    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class TopicHolder extends RecyclerView.ViewHolder {

        ImageView topic_imageView;
        TextView topic_title;
        TextView topic_type;

        public TopicHolder(View itemView) {
            super(itemView);
            topic_imageView = (ImageView) itemView.findViewById(R.id.topic_imageView);
            topic_title = (TextView) itemView.findViewById(R.id.topic_title);
            topic_type = (TextView) itemView.findViewById(R.id.topic_type);
        }
    }
}
